package org.example;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        ListNode listNode = new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5))));
        System.out.println(main.trainingPlan(listNode,2));
    }

    public ListNode trainingPlan(ListNode head, int cnt) {
        ListNode latter = head, former = head;
        // 快指针先走cnt步
        for(int i = 0; i < cnt; i++) {
            former = former.next;
        }
        // 快慢指针一起走
        while(former != null) {
            former = former.next;
            latter = latter.next;
        }
        // 返回慢指针
        return latter;
    }
}